cd "/Users/john/Dropbox/Turnout/TurnoutProjectNotes/WhoVotes/SurveyStuff"

use Replication_Prelim.dta, clear



********Demographics
***Sex
gen male=1 if q135==1
replace male=0 if q135==2

**YOB
gen yob=q136_god
gen age=2016-yob
replace age=. if yob==98

**Employed
gen employed=1 if q31==1
replace employed=0 if q31==2

 **Education
 gen educ=q137
 replace educ=. if educ==97 | educ==98

***Town size
gen townsize=tnp
*to make larger values larger cities
recode townsize (2=5) (3=4) (4=3) (5=2) (6=1) (1=6)
**Note:  the last two digits of "tip" can be used to create a more fine-grained measure of town size.  These provide a ten-point scale of population point size.  See email from Grazhdankin on 12/10/16


***KPSS
gen kpss=1 if q140==1
replace kpss=0 if q140>1


**Subjective economic condition
gen econ=q144
replace econ=. if econ==97 | econ==98


gen income=q151
replace income=. if income==7 | income==8
gen logincome=ln(income)


***Civil Society
gen union=1 if q152a==2
gen work=1 if q152b==2
gen church=1 if q152c==2
gen sport=1 if q152d==2
gen music=1 if q152e==2
gen ecology=1 if q152f==2
gen prof=1 if q152g==2
gen charity=1 if q152h==2
gen youth=1 if q152i==2


egen number_org=rowtotal(union-youth)



***Change in economic condition
gen change_econ=q145
replace change_econ=. if change_econ==7 | change_econ==8
gen change_econ1=1+5-change_econ
drop change_econ
rename change_econ1 change_econ

**Subjective economic evaluation
gen econ_eval=q149
replace econ_eval=. if econ_eval==7 | econ_eval==8
recode econ_eval (5=1) (4=2) (2=4) (1=5)

**Performance
gen corruption_worse=3 if q119a==1
replace corruption_worse=2 if q119a==2
replace corruption_worse=1 if q119a==3

gen inequality_worse=3 if q119b==1
replace inequality_worse=2 if q119b==2
replace inequality_worse=1 if q119b==3

gen stability_worse=3 if q119c==3
replace stability_worse=2 if q119c==2
replace stability_worse=1 if q119c==1

gen cauc_worse=3 if q119d==3
replace cauc_worse=2 if q119d==2
replace cauc_worse=1 if q119d==1

gen influence_worse=3 if q119e==3
replace influence_worse=2 if q119e==2
replace influence_worse=1 if q119e==1

gen econ_worse=3 if q119h==3
replace econ_worse=2 if q119h==2
replace econ_worse=1 if q119h==1

gen econ_better=3 if econ_worse==1
replace econ_better=2 if econ_worse==2
replace econ_better=1 if econ_worse==3



**Russian ethnicity
gen russian=1 if qn138==1
replace russian=0 if russian~=1 & qn138~=998




********Media
gen tv=1 if q4==1
replace tv=0 if q4==2

**Gen internet news
gen int_news=1 if q11b==1
replace int_news=0 if q11b==2 | q10==2

***int_news_scale
gen int_news_scale=q14
replace int_news_scale=. if q14==7 | q14==8
recode int_news_scale (5=1) (4=2) (2=4) (1=5)
replace int_news_scale=1 if q10==2

**sources
gen main_tv=1 if q15==1
replace main_tv=0 if q15==2 | q15==3 | q15==4

gen main_radio=1 if q15==2
replace main_radio=0 if q15==1 | q15==3 | q15==4

gen main_pap=1 if q15==3
replace main_pap=0 if q15==2 | q15==1 | q15==4

gen main_int=1 if q15==4
replace main_int=0 if q15==2 | q15==3 | q15==1


gen tv_main_news=1 if q15==1
replace tv_main_news=0 if q15==2 | q15==4 | q15==3

gen first=1 if q7a==1
replace first=0 if q7a==2 | q7a==6

gen ross=1 if q7b==1
replace ross=0 if q7b==2 | q7b==6

gen ntv=1 if q7c==1
replace ntv=0 if q7c==2 | q7c==6

gen state_news=1 if first==1 | ross==1 | ntv==1
replace state_news=0 if state_news~=1 & ntv~=. & first~=. & ross~=.
replace state_news=0 if q5==2
replace state_news=0 if q6==6
replace state_news=0 if q4==2

gen frequent_state_news=state_news
replace frequent_state_news=0 if q6==3 | q6==4

label variable frequent_state_news "Frequent State News"



**Social Media
gen social_media=1 if q11h==1
replace social_media=0 if social_media~=1

gen political_usage=1 if social_media==1 & q13a==1
replace political_usage=0 if political_usage~=1



**********Political Interest**************************

gen follow_pol=q1
replace follow_pol=. if follow_pol==7 | follow_pol==8
recode follow_pol (4=1) (1=4) (2=3) (3=2)




**********Elections and Political Support**************************
gen putin_support=q20
replace putin_support=. if putin_support==7 | putin_support==8
recode putin_support (5=1) (4=2) (2=4) (1=5)


gen putin_express=q25
replace putin_express=. if putin_express==97 | putin_express==98

gen putin_delight=1 if putin_express==1 
replace putin_delight=0 if putin_express>1 & putin_express~=.
gen putin_sympathy=1 if putin_express==2
replace putin_sympathy=0 if putin_express>2  | putin_express<2
replace putin_sympathy=. if putin_express==.
gen putin_notbad=1 if putin_express==3
replace putin_notbad=0 if putin_express>3  | putin_express<3
replace putin_notbad=. if putin_express==.
gen putin_neutral=1 if putin_express==4
replace putin_neutral=0 if putin_express>4  | putin_express<4
replace putin_neutral=. if putin_express==.
gen putin_unsure=1 if putin_express==5
replace putin_unsure=0 if putin_express>5  | putin_express<5
replace putin_unsure=. if putin_express==.
gen putin_notgood=1 if putin_express==6
replace putin_notgood=0 if putin_express>6  | putin_express<6
replace putin_notgood=. if putin_express==.
gen putin_anti=1 if putin_express==7
replace putin_anti=0 if putin_express>7  | putin_express<7
replace putin_anti=. if putin_express==.
gen putin_distaste=1 if  putin_express==8
replace putin_distaste=0 if putin_express<8 & putin_express~=.
gen putin_hate=1 if putin_express==7 | putin_express==8
replace putin_hate=0 if putin_hate~=1 & putin_express~=.
gen putin_delight2=putin_delight
replace putin_delight2=1 if putin_express==2


gen ur_support=q62
replace ur_support=. if ur_support==97 | ur_support==98


****Electoral fairness


gen elec_honest=q27
replace elec_honest=. if elec_honest==7 | elec_honest==8
recode elec_honest (5=1) (4=2) (2=4) (1=5)

**Should russia be democ?
gen democ_good=q29_1
replace democ_good=. if democ_good==7 | democ_good==8
recode democ_good (1=4) (4=1) (2=3) (3=2)


**Russia a democracy?
gen russia_democ=q30
replace russia_democ=. if russia_democ==7 | russia_democ==8
recode russia_democ (2=0)



*Voted
gen voted=1 if q77==1
replace voted=0 if q77==2

**familty upset at you for not voting
gen familypressure_vote=1 if q80a==1
replace familypressure_vote=0 if q80a==2

**friends upset at you for not voting
gen friendspressure_vote=1 if q80b==1
replace friendspressure_vote=0 if q80b==2

**coworkers upset at you for not voting
gen coworkerpressure_vote=1 if q80c==1
replace coworkerpressure_vote=0 if q80c==2

gen pressure_vote=1 if coworkerpressure_vote==1 | friendspressure_vote==1 | familypressure_vote==1
replace pressure_vote=0 if coworkerpressure_vote==0 & friendspressure_vote==0 & familypressure_vote==0



**why did you vote?
label variable q84_1 "civic duty"
label variable q84_2 "habit"
label variable q84_3 "desire to help my candidate"
label variable q84_4 "express my political position"
label variable q84_5 "so that vote not stolen"
label variable q84_6 "someone asked me"
label variable q84_7 "it's the custom in my social setting"
label variable q84_8 "other"
label variable q84_9 "hard to answer"
label variable q84_10 "refuse"


***Duty
gen turnout_experiment=1 if q79==2
replace turnout_experiment=0 if q79==1 

label define turnout 0 "choice" 1 "civic duty"
label values turnout_experiment turnout


***Workplace Mobilization
gen discuss_pol=q42a
replace discuss_pol=. if discuss_pol==7 | discuss_pol==8
recode discuss_pol (2=0)

gen agit_material=q42c
replace agit_material=. if agit_material==7 | agit_material==8
recode agit_material (2=0)

gen transport=q42d
replace transport=. if transport==7 | transport==8
recode transport (2=0)

gen ask_vote=q42e
replace ask_vote=. if ask_vote==7 | ask_vote==8
recode ask_vote (2=0)
gen ask_vote1=ask_vote
replace ask_vote1=0 if employed==0

gen ask_rally=q42g
replace ask_rally=. if ask_rally==7 | ask_rally==8
recode ask_rally (2=0)


gen wp_buy=q42h
replace wp_buy=. if wp_buy==7 | wp_buy==8
recode wp_buy (2=0)

gen wp_threat=q42i
replace wp_threat=. if wp_threat==7 | wp_threat==8
recode wp_threat (2=0)

gen anywpmob=1 if wp_threat==1 | wp_buy==1 | ask_rally==1 | ask_vote==1 | transport==1 | agit_material==1 | discuss_pol==1
replace anywpmob=0 if wp_threat==0 & wp_buy==0 & ask_rally==0 & ask_vote==0 & transport==0 & agit_material==0 & discuss_pol==0
gen anywpmob1=anywpmob
replace anywpmob1=0 if employed==0



*Party Mobilization
gen anyparty=1 if q66a==1 | q66b==1 | q66c==1 | q66d==1
replace anyparty=0 if q66a==2 & q66b==2 & q66c==2 & q66d==2


**Any vote buy
gen votebuy=1 if wp_buy==1
replace votebuy=0 if wp_buy==0
replace votebuy=0 if employed==0
replace votebuy=1 if q66c==1
replace votebuy=0 if (q66c==2 | q66c==7 | q66c==8) & wp_buy~=1

**Any threat
gen threat=1 if wp_threat==1
replace threat=0 if wp_threat==0
replace threat=0 if employed==0
replace threat=1 if q66d==1
replace threat=0 if (q66d==2 | q66d==7 | q66d==8) & wp_threat~=1


***Support Policies
**Pension
gen pension=4 if q118a==1
replace pension=3 if q118a==2
replace pension=2 if q118a==3
replace pension=1 if q118a==4

**child
gen child=4 if q118c==1
replace child=3 if q118c==2
replace child=2 if q118c==3
replace child=1 if q118c==4

**term
gen term=4 if q118b==1
replace term=3 if q118b==2
replace term=2 if q118b==3
replace term=1 if q118b==4

**syria
gen syria=4 if q118h==1
replace syria=3 if q118h==2
replace syria=2 if q118h==3
replace syria=1 if q118h==4


**food sanctions
gen food=4 if q118g==1
replace food=3 if q118g==2
replace food=2 if q118g==3
replace food=1 if q118g==4

**Crimea
gen crimea=4 if q118d==1
replace crimea=3 if q118d==2
replace crimea=2 if q118d==3
replace crimea=1 if q118d==4





*Some Interactions
gen interact=russia_democ*democ_good
label variable interact "Russia Democracy*Support Democracy"

gen x=putin_support*corruption_worse






label variable age "Age"
label variable male "Male"
label variable townsize "Town Size"
label variable kpss "CPSU Membership"
label variable econ "Economic Status"
label variable change_econ "Egotropic Econ. Eval."
label variable econ_eval "Sociotropic Econ. Eval."
label variable educ "Education"
label variable number_org "Social Org. Membership"
label variable employed "Employed"
label variable follow_pol "Follow Politics"
label variable threat "Received Threat"
label variable votebuy "Received Vote Buying Offer"
label variable ask_vote1 "Employer Asked to Vote"
label variable anyparty "Mobilized by Party"
label variable ur_support "UR Support"

label variable elec_honest "Perceived Elec. Integrity"
label variable putin_delight2 "Putin: Pos. Emotions"
label variable putin_hate "Putin: Neg. Emotions"
label variable pressure_vote "Social Pressure"
label variable turnout_experiment "Duty to Vote"
label variable russia_democ "Russia Democracy"
label variable democ_good "Democracy Support"
label variable putin_support "Putin Support"
label variable crimea "Crimea Support"
label variable syria "Syria War Support"
label variable child "Anti-Gay Bill Support"
label variable food "EU Food Ban Support"
label variable term "Term Extension Support"
label variable pension "Pension Reform Support"
label variable voted "Voted"

label variable corruption_worse "Corruption Has Increased"
label variable x "Corruption X Putin Support"
label variable econ_better "Living Standards Better under Putin"
label variable russian "Ethnic Russian"




**Regional PR


gen d=putin_support*ur16

label variable d "Putin Support * Reg. Competition"
label variable ur16 "Reg. Competition"



***Performance Measures
**Creating, Rescaling, and Naming Variables
foreach var of varlist inequality_worse stability_worse influence_worse cauc_worse{
 gen `var'_flip = 3 if `var' == 1 
 replace `var'_flip =2 if `var' == 2
 replace `var'_flip =1 if `var' == 3
}


label variable inequality_worse_flip "Inequality Better"

label variable stability_worse_flip "Political Stability Better"
label variable influence_worse_flip "Foreign Influence Better"
label variable cauc_worse_flip "Caucasus Better"

rename inequality_worse_flip ineq

rename stability_worse_flip stab
rename  influence_worse_flip infl
rename cauc_worse_flip cauc

gen perf_index=econ_better+cauc+infl+stab+ineq

label variable perf_index "Performance Index"



***SMD stuff

**Dealing with instances when UR is not winner (1= no ur, but pro ur independent (just Reznik), 2 (no ur cand), 3 (UR loses))
gen no_ur=.
replace no_ur=1 if okrug==1
replace no_ur=2 if okrug==6 | okrug==34 | okrug==46 | okrug==60 | okrug==79 | okrug==117 | okrug==130 | okrug==140 | okrug==171 | okrug==185 | okrug==188 | okrug==190 | okrug==204 | okrug==206
replace no_ur=3 if okrug==83 | okrug==177
replace winner_margin=winner_margin*-1 if no_ur==3
replace winner_margin=0 if no_ur==2
rename winner_margin smd_winner_margin



gen f=putin_support*smd_winner_margin
label variable f "Putin Support * SMD Winner Margin"
label variable smd_winner_margin "SMD Winner Margin"






****Save Main Replication Data
save Final_Replication_Data, replace
